package com.woniuxy.portal.service.impl;

import com.woniuxy.comon.RedisConst;
import com.woniuxy.portal.mapper.BookMapper;
import com.woniuxy.portal.model.dto.CartVo;
import com.woniuxy.portal.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

@Service
public class CartServiceImpl implements CartService {

    @Autowired
    private RedisTemplate<String, CartVo> redisTemplate;

    @Autowired
    private BookMapper bookMapper;


    @Override
    public CartVo getCart(Long userId) {
        ValueOperations<String, CartVo> ops = redisTemplate.opsForValue();
        CartVo cart = ops.get(RedisConst.USER_CART_PREFIX + ":" + userId);

        if (cart == null) {
            cart = new CartVo();
            cart.setUserId(userId);
        }
        ops.set(RedisConst.USER_CART_PREFIX + ":" + userId, cart);
        return cart;
    }


    @Override
    public CartVo addCartItem(Long userId, Long bookId) {
        return null;
    }

    @Override
    public CartVo removeCartItem(Long userId, Long bookId) {
        return null;
    }


}
